<script type="text/javascript">
	$(document).ready(function(){
		$('select[name=vitrixh]').change(function(){
			$(this).parent().submit();
		});
		$('select[name=phanloai]').change(function(){
			$(this).parent().submit();
		});
		
		$('.phanloai').change(function(){
			if($(this).val()==0){
				$('.vtxh').show();
			}else{
				$('.vtxh').hide();
			}
		});
		$("#textarea").htmlarea({
                toolbar: ["html", "|",
                        "forecolor",  // <-- Add the "forecolor" Toolbar Button
                        "|", "bold", "italic", "underline", "|", "p", "h1", "h2", "h3", "|", "link", "unlink", "|", "image"] // Overrides/Specifies the Toolbar buttons to show
		});
		$("#PostAddProject").validate({ 
	        rules: { 
              "tieude":"required",
              "noidung":"required",
              "diachi":"required",
              "loban":"required",
	        }, 
	        messages: { 
              "tieude": "Nhập tiêu đề bài viết",
              "noidung": "Nhập nội dung bài viết",
              "diachi": "Nhập địa chỉ",
              "loban": "Nhập lô bán",
	        } 
		});
	});	
	
</script>
<div id="content">
	
	<!-- Box -->
	<div class="box">
		<!-- Box Head -->
		<div class="box-head">
			<h2 class="left">Các dự án hiện tại</h2>
			<!--<div class="right">
				<input type="text" class="field small-field" id="search-duan" />
				<input type="submit" class="button" value="Tìm kiếm" />
			</div>-->
		</div>
		<!-- End Box Head -->	

		<!-- Table -->
		<div class="table">
			<table width="100%" border="0" cellspacing="0" cellpadding="0">
				<tr>
					<th width="13">STT</th>					
					<th width="10%"><?php echo $this->Paginator->sort('Tiêu đề', 'tieude');?></th>
					<th width="30%"><?php echo $this->Paginator->sort('Nội dung','noidung');?></th>
					<th><?php echo $this->Paginator->sort('Vị trí xuất hiện','vitrixh');?></th>
					<th width="200"><?php echo $this->Paginator->sort('Địa chỉ','diachi');?></th>
					<th><?php echo $this->Paginator->sort('Phân loại','phanloai');?></th>
					<th width="10%"><?php echo $this->Paginator->sort('Lô bán','loban');?></th>
					<th width="100"><?php echo $this->Paginator->sort('Ngày đăng','ngaydang');?></th>
					<th width="50" class="ac">Điều khiển</th>
				</tr>
				<?php
				$i = 0;
				$dem = 0;
				foreach ($duans as $duan):
					$class = null;
					if ($i++ % 2 == 0) {
						$class = ' class="altrow"';
					}
					$dem ++;
				?>
				<tr>
					<td><?php echo $dem;?></td>
					<td><h3><a href="#"><?php echo $duan['Duan']['tieude']; ?></a></h3></td>
					<td><?php echo $duan['Duan']['noidung']; ?></td>
					<?php if($duan['Duan']['phanloai'] == 0){?>
					<td>
						<form name="changevitrixh" id="changevitrixh" method="post" action="<?php echo $this->webroot;?>duans/change_vitrixh">
							<input type="hidden" name="idduan" value="<?php echo $duan['Duan']['id'];?>" />
							<select name="vitrixh">
								<?php
									for($i=1; $i<=10; $i++){
										if($i==$duan['Duan']['vitrixh']){
											echo '<option selected value="'.$i.'">'.$i.'</option>';
										}else{
											echo '<option value="'.$i.'">'.$i.'</option>';
										}
									}
								?>
								
							</select>
						</form>
					</td>
					<?php }else{ ?>
					<td></td>
					<?php } ?>
					<td><?php echo $duan['Duan']['diachi']; ?></td>
					<td>
						<form id="phanloai" method="post" action="<?php echo $this->webroot;?>duans/phanloai">
						<input type="hidden" name="idduan" value="<?php echo $duan['Duan']['id'];?>" />
						<select name="phanloai">
						<?php
							for($i=0; $i<=1; $i++){
								if($i==$duan['Duan']['phanloai']){
									if($i==1){
										echo '<option selected value="'.$i.'">Dự án vip</option>';
									}else{
										echo '<option selected value="'.$i.'">Dự án thường</option>';
									}
								}else{
									if($i==1){
										echo '<option value="'.$i.'">Dự án vip</option>';
									}else{
										echo '<option value="'.$i.'">Dự án thường</option>';
									}
								}
							}
						?>
						</select>
						</form>
					</td>
					<td><?php echo $duan['Duan']['loban']; ?></td>
					<td><?php echo $duan['Duan']['ngaydang']; ?></td>
					<td class="dieukhien"><?php echo $this->Html->link(__('Delete', true), array('action' => 'admin_delete', $duan['Duan']['id']), null, sprintf(__('Bạn chắc chắn muốn xóa dự án này?', true), $duan['Duan']['id'])); ?><?php echo $this->Html->link(__('Edit', true), array('action' => 'admin_edit', $duan['Duan']['id'])); ?></td>
				</tr>
				<?php endforeach; ?>
				
			</table>
			
			
			<!-- Pagging -->
			<div class="paging">
				<?php echo $this->Paginator->prev('<< ' . __('previous', true), array(), null, array('class'=>'disabled'));?>
			 | 	<?php echo $this->Paginator->numbers();?>
		 |
				<?php echo $this->Paginator->next(__('next', true) . ' >>', array(), null, array('class' => 'disabled'));?>
			</div>
			<!--<div class="pagging">
				<div class="left">Showing 1-12 of 44</div>
				<div class="right">
					<a href="#">Previous</a>
					<a href="#">1</a>
					<a href="#">2</a>
					<a href="#">3</a>
					<a href="#">4</a>
					<a href="#">245</a>
					<span>...</span>
					<a href="#">Next</a>
					<a href="#">View all</a>
				</div>
			</div>-->
			<!-- End Pagging -->
			
		</div>
		<!-- Table -->
		
	</div>
	<!-- End Box -->
	
	<!-- Box -->
	<div class="box">
		<!-- Box Head -->
		<div class="box-head">
			<h2>Thêm dự án</h2>
		</div>
		<!-- End Box Head -->
		
		<form id="PostAddProject" method="post" enctype="multipart/form-data" action="<?php echo $this->webroot;?>/duans/admin_add">
			
			<!-- Form -->
			<div class="form">
					<p>
						<label>Tên dự án <span class="require-field">(*)</span></label>
						<input class="field size1"  type="text" name="tieude"/>
					</p>
					<p>
						<label>Nội dung <span class="require-field">(*)</span></label>
						<textarea id="textarea" class="field size1"  rows="10" cols="30" name="noidung"></textarea>
					</p>
					<p>
						<label>Hình đại diện</label>
						<input class="field size1"  type="file" name="hinhdaidien" />
					</p>
					<p>
						<label>Địa chỉ <span class="require-field">(*)</span></label>
						<input class="field size1"  type="text" name="diachi"  />
					</p>
					<p>
						<label>Phân loại</label>
						<select name="phanloai" class="phanloai">
							<option value="0">Dự án thường</option>
							<option value="1">Dự án vip</option>
						</select>
					</p>
					<p>
						<label>Lô bán <span class="require-field">(*)</span></label>
						<input class="field size1"  type="text" name="loban" />
					</p>
					<p class="vtxh">
						<label>Vị trí xuất hiện</label>
						<select name="vitrixh">
							<option value="1">1</option>
							<option value="2">2</option>
							<option value="3">3</option>
							<option value="4">4</option>
							<option value="5">5</option>
							<option value="6">6</option>
							<option value="7">7</option>
							<option value="8">8</option>
							<option value="9">9</option>
							<option value="10">10</option>
						</select>
					</p>						
			</div>
			<!-- End Form -->
			
			<!-- Form Buttons -->
			<div class="buttons">				
				<input type="submit" class="button" value="Đăng dự án" />
			</div>
			<!-- End Form Buttons -->
		</form>
	</div>
	<!-- End Box -->

</div>